<html>
<head><meta charset="utf-8"><title>expanding target specs with cache padding information · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html">expanding target specs with cache padding information</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216255743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216255743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216255743">(Nov 10 2020 at 18:47)</a>:</h4>
<p>In <a href="#narrow/stream/219381-t-libs/topic/.60std.3A.3Amem.3A.3ACachePadded.60">https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60std.3A.3Amem.3A.3ACachePadded.60</a> we've been talking about adding <code>std::mem::CachePadded</code> to the stdlib. One thing that's come up is that the current cache padding implementations are not good enough as they make too broad assumptions.</p>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> suggested the right solution would be to add cache padding information to the <a href="https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/spec">target specs</a>. Unless I'm missing something it appears we only track triples, and not specific CPUs. What would be the right way to add this information into the stdlib so that we can later use it to set the alignment of <code>std::mem::CachePadded</code>?</p>



<a name="216256027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216256027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216256027">(Nov 10 2020 at 18:49)</a>:</h4>
<p>as a first step, I think it would just be making similar broad assumptions (like treating all <code>x86_64</code> the same), but doing that in target specs is a bit more principled</p>



<a name="216256208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216256208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216256208">(Nov 10 2020 at 18:50)</a>:</h4>
<p>I don't see any precedent of using <code>target-cpu</code> in the standard library though</p>



<a name="216256282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216256282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216256282">(Nov 10 2020 at 18:50)</a>:</h4>
<p>especially since <code>std</code> is currently precompiled for the generic target</p>



<a name="216261055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216261055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216261055">(Nov 10 2020 at 19:23)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> cool, that makes sense! Had no idea the stdlib was precompiled, but that makes a lot of sense now that I think about it. — yes cool that makes a lot of sense to start</p>



<a name="216265573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216265573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216265573">(Nov 10 2020 at 19:58)</a>:</h4>
<p>(There's long been a wish to have <code>std</code> not just be the one precompiled one -- it's be nice to have <code>debug_assert</code>ions work in debug mode, for example -- but I don't know what the progress of that is.  Maybe the <code>std</code>-aware cargo stuff?)</p>



<a name="216335953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216335953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216335953">(Nov 11 2020 at 11:53)</a>:</h4>
<p>I'm not sure what the state of field alignment annotations is but to some degree instead of catch padded something like <code>struct S { #[align(cach_size)]  f: AtomicUsize }</code>  could be used. (Edit: to work well with precompiled std)</p>
<p>Except that due to different caches, unusual cache sizes and other things which need to be considered (e.g. for   ll/sc atomic operations) we probably should not use cache size as terminology.</p>
<p>While C++ hardware_destructive_inference_size  isn't necessary the most intuitive name, it's more or less the feature we need instead of cache size based alignment/paying I think.</p>



<a name="216336447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216336447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216336447">(Nov 11 2020 at 11:59)</a>:</h4>
<p>This also would work with less specify targets as in a certain way it would hint the smallest size most likely guaranteed to avoid unwanted inference.</p>



<a name="216336815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/expanding%20target%20specs%20with%20cache%20padding%20information/near/216336815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/expanding.20target.20specs.20with.20cache.20padding.20information.html#216336815">(Nov 11 2020 at 12:03)</a>:</h4>
<p>Anyway this probably requires some form of "extended" target spec I guess?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>